import java.util.Arrays;

public class LeetCode1636 {
    public static int[] frequencySort(int[] nums) {
        //统计出现频率
        int[] count = new int[201];
        for (int num : nums) {
            count[num + 100]++;
        }
        //2.比较器 按频率升序
        return Arrays.stream(nums).boxed().sorted((a, b) -> {
            int af = count[a + 100];
            int bf = count[b + 100];
            if (af < bf) {
                return -1;
            } else if (af > bf) {
                return 1;
            } else {
                return b - a;
            }
        }).mapToInt(Integer::intValue).toArray();
    }

    public static void main(String[] args) {
        int[] nums = {2, 3, 1, 3, 2};
        int[] ints = frequencySort(nums);
        System.out.println(Arrays.toString(ints));
    }
}
